
#include <Windows.h>

#include <QResource>
#include <QTcpSocket>
#include <QHostAddress>

#include <Constance.h>

#include "Server.h"
Server::Server()
{
	QResource::registerResource("resources.rcc");
	QTcpSocket s;
	s.connectToHost(QHostAddress::LocalHost, TC::Constance::numbers.port);
	if (!s.waitForConnected())
	{
		char cmd[256] = "TCServer.exe";
		STARTUPINFOA si = {};
		si.cb = sizeof(si);
		PROCESS_INFORMATION pi = {};
		CreateProcessA(nullptr, cmd, nullptr, nullptr, false, CREATE_NEW_CONSOLE, nullptr, nullptr,
			&si, &pi);

		s.connectToHost(QHostAddress::LocalHost, TC::Constance::numbers.port);
		while(!s.waitForConnected())
			s.connectToHost(QHostAddress::LocalHost, TC::Constance::numbers.port);
	}
}
